package com.hmall.api.fallback;

import com.hmall.api.ItemClient;
import com.hmall.api.dto.ItemDTO;
import com.hmall.api.dto.OrderDetailDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

@Slf4j
public class ItemClientFallback implements FallbackFactory<ItemClient> {
    @Override
    public ItemClient create(Throwable cause) {
        log.error(cause.getMessage(), cause);
        return new ItemClient(){
            @Override
            public List<ItemDTO> queryItemByIds(Collection<Long> ids) {
                log.info("ItemFallbackFactory item服务降级");
                return new ArrayList<>();
            }
            @Override
            public void deductStock(List<OrderDetailDTO> items) {
                throw new RuntimeException("item 服务异常");
            }
        };
    }
}
